/*
 * Utiles_Varios.java
 *
 * Created on 23 de agosto de 2007, 9:09
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package helper;
import java.util.*;
import javax.swing.table.*;
import javax.swing.*;

/**
 *
 * @author EPSGRAU
 */
public class Utiles_Varios {
    
    /** Creates a new instance of Utiles_Varios */
    public Utiles_Varios() {
    }
    
    public static int[] clonarArreglo( int[] arr ){
        int[] arreglo = new int[ arr.length ];
        for( int i = 0; i < arr.length; i++ ){
            arreglo[ i ] = arr[ i ];
        }
        return arreglo;
    }
    
    public static String getCadena( ArrayList al ){
        String cad = "";
        for( int i = 0; i < al.size(); i++ ){
            cad = cad + " " + ( al.get( i ).toString() ).trim();
        }
        return cad;
    }
    
    public static void centraCeldasTabla( javax.swing.JTable jt ){
        int c = jt.getColumnCount();
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();        
        tcr.setHorizontalAlignment(SwingConstants.CENTER);
                             
        //Alineaci�n de Detalle
        for( int i = 0; i < c; i++ ){        
            jt.getColumnModel().getColumn( i ).setCellRenderer( tcr );
        }        
    }
    
    public static void alineaColumnasTabla( javax.swing.JTable jt, int col[] ){
        int c = jt.getColumnCount();
        
        for( int i = 0; i < c; i++ ){
            DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
            switch( col[i] ){                            
                case 0:                   
                    tcr.setHorizontalAlignment(SwingConstants.LEFT);
                    break;                       
                case 1:
                    tcr.setHorizontalAlignment(SwingConstants.CENTER);
                    break;
                case 2:
                    tcr.setHorizontalAlignment(SwingConstants.RIGHT);
                    break;
            }
            jt.getColumnModel().getColumn( i ).setCellRenderer( tcr );
        }                        
    }
        
    public static void llenaComboString( ArrayList res, JComboBox cmb, int col ){        
        ArrayList temp;
        for( int i = 0; i < res.size() - 2; i++ ){
            temp = ( ArrayList ) res.get( i );
            cmb.addItem( temp.get( col - 1 ) );
        }
    }
    
    public static HashMap getHashMapParametros( String[][] arr ){        
        HashMap hm = new HashMap();
        for( int i = 0; i < arr.length; i++ ){
            hm.put( arr[ i ][ 0 ], arr[ i ][ 1 ] );
        }        
        return hm;
    }
    
    public static boolean isContenido( int[] arr, int n ){
        for( int i = 0; i < arr.length; i++ ){
            if( arr[ i ] == n ){
                return true;
            }
        }
        return false;
    }

    public static ArrayList convertirListToArrayList( List datos ){
        ArrayList arrayList = new ArrayList(1), temp = new ArrayList(1);
        String d1;
         for( Object obj : datos ){
            List array = ((List) obj);
            temp = new ArrayList(1);
            for( Object obj1 : array ){
                try {
                    d1 = obj1.toString();
                } catch (Exception e) {
                    d1 = "";
                }
                temp.add(d1);
            }
            arrayList.add(temp);
         }
         return arrayList;
    }
    public final static int ALINEA_IZQUIERDA = 0;
    public final static int ALINEA_CENTRO = 1;
    public final static int ALINEA_DERECHA = 2;    
}
